package com.melody.rest.util;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class ResourceVerification {
    //权限比较
    private List<String> resources = new ArrayList<>();

    public Boolean compareResource(String temp){
        initResources();
        if (resources.contains(temp)){
            return true;
        }
        return false;
    }
    public void initResources(){
        //模拟用户权限
        resources.add("/rest/test1");
        resources.add("/rest/test2");
        resources.add("/rest/test3");
        resources.add("/rest/test4");
    }

    //模拟实现从数据库获取资源
    public static List<String> resource(){
        List<String> resourcesUser = new ArrayList<>();
        resourcesUser.add("/testRest/t1");
        resourcesUser.add("/testRest/t2");
        resourcesUser.add("/testRest/t3");
        resourcesUser.add("/testRest/t4");

        return resourcesUser;
    }

    //是否包含该权限
    public Boolean compareResourceRest(List<String> resources,String auth){
        if (auth.length()!=0) {
           if(resources.contains(auth)){
               return true;
           }
        }
        return false;
    }
}
